﻿using System;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YJKRevitPipeSetting.DataDefine;

namespace YJKRevitPipeSetting
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdDeletePipe : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Document document = commandData.Application.ActiveUIDocument.Document;
			Transaction transaction = new Transaction(document, "DeletePipeOccupied");
			transaction.Start();
			foreach (Element element in new FilteredElementCollector(document).OfClass(typeof(FamilyInstance)).WhereElementIsNotElementType().ToElements())
			{
				FamilySymbol symbol = (element as FamilyInstance).Symbol;
				if (TypeFileInfo.OccupiedType.Contains(symbol.Family.Name))
				{
					document.Delete(element.Id);
				}
				if (TypeEquipmentInfo.OccupiedType.Contains(symbol.Family.Name))
				{
					document.Delete(element.Id);
				}
			}
			transaction.Commit();
			YJKMessageBox.Show("成功删除所有占位");
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
